package com.ddone.finance.controller.api;


import com.baomidou.mybatisplus.extension.api.R;
import com.ddone.base.util.JwtUtils;
import com.ddone.common.result.Response;
import com.ddone.finance.pojo.vo.BorrowerDetailVo;
import com.ddone.finance.pojo.vo.BorrowerVo;
import com.ddone.finance.service.BorrowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author ddone
 * @since 2024-04-10
 */
@Api(tags = "借款人")
@RestController
@RequestMapping("/core/api/borrower")
@Slf4j
public class BorrowerController {

    @Resource
    private BorrowerService borrowerService;

    @ApiOperation("保存借款人信息")
    @PostMapping()
    public Response<Object> save(@Valid @RequestBody BorrowerVo borrowerVO, @RequestHeader("token") String token) {
        Long userId = JwtUtils.getUserId(token);
        borrowerService.saveBorrowerVoByUserId(borrowerVO, userId);
        return Response.ok().message("信息提交成功");
    }

    @ApiOperation("获取借款人认证状态")
    @GetMapping("/authStatus")
    public Response<Object> getBorrowerStatus(@RequestHeader("token") String token){
        Long userId = JwtUtils.getUserId(token);
        Integer status = borrowerService.getStatusByUserId(userId);
        return Response.ok(status);
    }
}

